<?php
//
// EnewsController.class.php
//

// Direct access protection
if( !defined( 'LIRIOPE' )) die( 'Direct access is not allowed.' );

class EnewsController extends LiriopeController {

  function show($vars=NULL) {
    $page = $this->getPage();

    $issues = $this->getIssues();
    // use the last # issues
    $issues = array_slice($issues, 0, 10, TRUE);

    $page->set('issues', $issues);
  }

  function issue($vars=NULL) {
    $page = $this->getPage();

    $id = a::get($vars, 'id');
    $issues = $this->getIssues();
    $issue = $issues[$id];

    $page->set('issue',$issue);
  }

  function getIssues() {
    $file = load::exists('enews.yml', 'data');
    $yaml = new Yaml($file);
    $issues = array();
    foreach($yaml->get() as $i) {
      $date = date('Y-m-d', strtotime($i->date));
      $issues[$date] = $i;
    }
    return $issues;
  }
}

